package com.liqin.nothing.controller;

import com.liqin.nothing.entity.Person;
import com.liqin.nothing.entity.User;
import com.liqin.nothing.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ghl
 * @since 2024/1/11 上午 11:44
 */

@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    @GetMapping("/getAllUser")
    public List<User> getAllUser() {
        return userService.getAllUser();
    }

    @GetMapping("/insertBatch")
    public void insertBatch() {
        ArrayList<User> users = new ArrayList<>();
        for (int i = 0; i < 1001; i++) {
            User user = new User();
            user.setName("张三" + i);
            users.add(user);
        }
        log.info(LocalDateTime.now() + "--开始导入");
        userService.saveBatch(users);
        log.error(LocalDateTime.now() + "--结束导入");
    }

    @GetMapping("/getPerson")
    public Person getPerson() {
        return userService.getPerson();
    }


}
